package com.example.weixinauth.controller;

import com.example.weixinauth.feign.FeignLoginService;
import com.weixin.common.core.domain.Result;
import com.weixin.common.core.form.LoginForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

/**
 * @version 1.0.0
 * @className: LoginController
 * @description: 微服务授权校验
 * @author: zhangjunfa
 * @date: 2023/6/19 16:06
 */
@Slf4j
@RequestMapping
@RestController
public class AuthController {
    private FeignLoginService loginService;

    public AuthController(FeignLoginService loginService) {
        this.loginService = loginService;
    }

    @PostMapping(name = "/login")
    public Result<?> login(LoginForm loginForm) {
        return loginService.login(loginForm);
    }

    @PostMapping(name = "/logout")
    public Result<?> logout(HttpServletRequest request) {
        this.loginService.logout(request);
        return Result.ok();
    }

    @PostMapping(name = "/register")
    public Result<?> register(LoginForm loginForm) {
        this.loginService.register(loginForm);
        return Result.ok();
    }

    @PostMapping(name = "/refreshToken")
    public Result<?> refreshToken(HttpServletRequest request) {
        this.loginService.refreshToken(request);
        return Result.ok();
    }
}
